<!-- 使用 type="home" 属性设置首页，其他页面不需要设置，默认为page；推荐使用json5，更强大，且允许注释 -->
<route lang="json5">
{
  style: {
    navigationBarTitleText: '销售出库',
    custom: true,
  },
}
</route>
<template>
  <Loyout class="outorder-page" bgc="#F3F8FE">
    <view class="out-page">
      <wd-form ref="form" :model="outFormdata">
        <wd-cell-group border>
          <wd-input
            type="text"
            v-model="outFormdata.out_order_no"
            label="单号"
            prop="outOrderNo"
            suffix-icon="list"
          />
          <wd-picker :columns="lstOrg" label="往来单位" v-model="outFormdata.org_code" />
          <wd-picker
            :columns="Lst_order_goods_type"
            label="模式"
            v-model="outFormdata.goods_type"
          />
        </wd-cell-group>
      </wd-form>
    </view>
    <template #footer>
      <wd-button class="flex1 ml-20" size="large" @click="startScan">开始扫描</wd-button>
    </template>
  </Loyout>
</template>

<script lang="ts" setup>
import Loyout from '@/layouts/index.vue'
import { useOrderConfigStore } from '@/store/orderconfig'
import { getNewOutOrderNo } from './out-utils'
import { Lst_order_goods_type, GoodsType, OrderType, OutOrderStatus } from '@/enum'
import OutSqlLite, { OutorderTable } from '@/utils/out-sqlite'
const orderConfigStore = useOrderConfigStore()

const outFormdata = reactive<OutorderTable>({
  out_order_no: '',
  org_code: '',
  goods_type: GoodsType.NORMAL,
  order_type: OrderType.OUT,
  create_at: '',
  status: OutOrderStatus.UNEXPORT,
  delete_flag: '0',
})
const lstOrg = [
  {
    value: '1',
    label: '测试组织1',
  },
  {
    value: '2',
    label: '测试组织2',
  },
]

const orderConfig = computed(() => orderConfigStore.orderConfig)

onLoad(() => {
  // 是否自动生成单号
  if (orderConfig.value.autoOrderNo) {
    outFormdata.out_order_no = getNewOutOrderNo()
  }
})

const startScan = async () => {
  const data = await OutSqlLite.insert([outFormdata])
  // 跳转到扫描页面
  uni.navigateTo({
    url: `/pages/outorder/out-item?out_order_no=${outFormdata.out_order_no}`,
  })
}
</script>
